package club.haomoon.front.service.impl;

import club.haomoon.core.enums.YesNoEnum;
import club.haomoon.core.mapper.article.DecorateTabbarDataMapper;
import club.haomoon.core.util.DateUtil;
import club.haomoon.core.util.StringUtils;
import club.haomoon.core.util.UrlUtil;
import club.haomoon.front.service.IDecorateTabbarService;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import club.haomoon.front.data.article.DecorateTabbarData;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * -------------------------
 * @Description: 底部导航服务实现类
 * @Author: Wangjianwei
 * @Date: 2025/02/24 14:16
 * -------------------------
 */
@Service
public class DecorateTabbarServiceImpl implements IDecorateTabbarService {

    @Resource
    DecorateTabbarDataMapper decorateTabbarDataMapper;


    @Override
    public List<DecorateTabbarData> getTabbarLists() {
        List<club.haomoon.core.entity.article.DecorateTabbarData> list = decorateTabbarDataMapper.selectList(new QueryWrapper<club.haomoon.core.entity.article.DecorateTabbarData>().eq("is_show", YesNoEnum.YES.getCode()));
        List<DecorateTabbarData> ret = new ArrayList<DecorateTabbarData>();
        if (list.size() == 0) {
            return ret;
        }

        for (club.haomoon.core.entity.article.DecorateTabbarData item : list) {
            DecorateTabbarData vo = new DecorateTabbarData();
            BeanUtils.copyProperties(item, vo);
            if (StringUtils.isNotEmpty(item.getSelected())) {
                vo.setSelected(UrlUtil.toAbsoluteUrl(item.getSelected()));
            }

            if (StringUtils.isNotEmpty(item.getUnselected())) {
                vo.setUnselected(UrlUtil.toAbsoluteUrl(item.getUnselected()));
            }

            vo.setCreateTime(DateUtil.timestampToDate(item.getCreateTime()));
            vo.setUpdateTime(DateUtil.timestampToDate(item.getUpdateTime()));
            vo.setLink(StringUtils.isEmpty(item.getLink()) ? new JSONObject() : JSONObject.parse(item.getLink()));
            ret.add(vo);
        }
        return ret;
    }
}
